 /*///////////////////////////////////////////////////////////////////////////////
-- Author:      liuhx
-- Created:     Fri Nov 16 11:53:48 CST 2018
-- Description:
-- If you have any question,please email to liuhx@gentlesoft.com.cn
////////////////////////////////////////////////////////////////////////////////*/
package com.ctsi.product.service;

 import com.ctsi.commons.util.UtilValidate;
 import com.ctsi.commons.util.id.UUIDGenerator;
 import com.ctsi.commons.util.response.Page;
 import com.ctsi.framework.mybatis.support.MybatisGenericDao;
 import com.ctsi.product.entity.ProductLibrary;
 import com.ctsi.product.vo.LeaderCockpitVO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;

 import java.util.List;
 import java.util.Map;


/**
 * ProductLibrary Service 类
 * @author   liuhx
 * @description  ProductLibrary
 * @created	 Fri Nov 16 11:53:48 CST 2018
 */

@Service
public class ProductLibraryService {
	private static final Logger logger=LoggerFactory.getLogger(ProductLibraryService.class);
	@Autowired
	private MybatisGenericDao dao;

/**
 * 领导驾驶舱接口
 */
public List<LeaderCockpitVO> selectLeaderCockpit(){
	logger.debug("selectLeaderCockpit {}");
	return (List<LeaderCockpitVO>) dao.queryForList(ProductLibrary.class.getName()+".selectLeaderCockpit");
}
	/**
	 * 实时更新评论数量
	 */
	public int updatePinLunNumById(ProductLibrary productLibrary){
		logger.debug("updatePinLunNumById {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".updatePinLunNumById",productLibrary);
	}
	/**
	 * 实时更新点赞数量
	 */
	public int updateDianZanNumById(ProductLibrary productLibrary){
		logger.debug("updateDianZanNumById {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".updateDianZanNumById",productLibrary);
	}
	/**
	 * 实时更新浏览数量
	 */
	public int updateLiuLanNumById(ProductLibrary productLibrary){
		logger.debug("updateLiuLanNumById {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".updateLiuLanNumById",productLibrary);
	}
	/**
	 * 实时更新收藏数量
	 */
	public int updateShouCangNumById(ProductLibrary productLibrary){
		logger.debug("updateShouCangNumById {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".updateShouCangNumById",productLibrary);
	}

	/**
	 * 根据productId获取该产品信息
	 */
	public ProductLibrary selectProductById(String id){
		logger.debug("selectProductById {}",id);
		return (ProductLibrary) dao.queryForObject(ProductLibrary.class.getName()+".selectProductById",id);
	}


	/**
	 * 产品详情get发布人
	 */
	/*public ProductLibrary selectProductByIdAndGetMan(String id){
		logger.debug("selectProductByIdAndGetMan {}",id);
		return (ProductLibrary) dao.queryForObject(ProductLibrary.class.getName()+".selectProductByIdAndGetMan",id);
	}*/

	/**
	 * 新增产品
	 */
	public int insertProductLibrary(ProductLibrary productLibrary){
		if(UtilValidate.isEmpty(productLibrary.getId()))
			productLibrary.setId(UUIDGenerator.getId());
		logger.debug("insert {}",productLibrary);
		return dao.insert(productLibrary);
	}

	/**
	 * 修改产品
	 */
	public int updateByPrimaryKeySelective(ProductLibrary productLibrary){
		logger.debug("updateByPrimaryKeySelective {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".updateByPrimaryKeySelective", productLibrary);
	}
	/**
	 * 删除产品
	 */
	public int deleteByPrimaryKey(ProductLibrary productLibrary){
		logger.debug("update {}",productLibrary);
		return dao.update(ProductLibrary.class.getName()+".deleteByPrimaryKey",productLibrary);
	}

	/**
	 * 根据ID查找 ProductLibrary对象
	 */
	public ProductLibrary findProductLibraryById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(ProductLibrary.class, id);
	}
	/**
	 * 删除ProductLibrary对象
	 */
	public int removeProductLibrary(String id){
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(ProductLibrary.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}

	/**
	 * 详细页查询
	 */
	public ProductLibrary findByDetail(String id){
		return (ProductLibrary)dao.queryForObject(ProductLibrary.class.getName()+".findByDetail",id);
	}
	/**
	 *  根据条件查询产品列表
	 */
	public Page<ProductLibrary> queryListProductLib(Map<String,Object> param , int start , int pageSize){
		logger.debug("queryListProductLib {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(ProductLibrary.class.getName()+".queryListProductLib", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 多条件查询结果不分页
	 */
	public List<ProductLibrary> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<ProductLibrary>)dao.queryForList(ProductLibrary.class.getName()+".selectByMap",map);
	}
	/*
	* 登陆用户评论过的产品-列表
	* */
	public Page<ProductLibrary> selectProLibByLoginId(Map<String,Object> param , int start , int pageSize){
		logger.debug("selectProLibByLoginId {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(ProductLibrary.class.getName()+".selectProLibByLoginId", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 登陆用户收藏产品
	 */
	public Page<ProductLibrary> selectProCollectByUserId(Map<String,Object> param , int start , int pageSize){
		logger.debug("selectProCollectByUserId {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(ProductLibrary.class.getName()+".selectProductListCollect", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/**
	 * 登陆用户学习记录
	 */
	public Page<ProductLibrary> selectProStudyByUserId(Map<String,Object> param , int start , int pageSize){
		logger.debug("selectProStudyByUserId {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(ProductLibrary.class.getName()+".selectProLiulanListCollect", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
}
